package com.sjdang.springcloud.learning.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.sjdang.springcloud.learning.service.NacosFeignService;

@RestController
@RequestMapping("/learning/nacos/sentinel")
public class NacosSentinelController {
	
	private Logger log = LoggerFactory.getLogger(this.getClass());
	
	@Resource
	private NacosFeignService nacosFeignService;
	
	@Value("${server.port}")
	private String port;
	
	@GetMapping("/hello")
	@SentinelResource(value="/learning/nacos/sentinel/hello", fallback="sayError")
	public String sayHello(@RequestParam(value="name", defaultValue="Nacos")String name) {
		log.info("nacos-sentinel is called  ");
		return nacosFeignService.sayHello(name);
	}
	
	public String sayError(String name) {
		return "Hi, " + name + ", I am so sorry for error, please try again later.";
	}
	
}
